package com.hmdp.config;

import com.hmdp.Intecepter.LoginIntercepetor;
import com.hmdp.Intecepter.ReflushIntereptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.annotation.Resource;

/**
 * @author zkx
 */
@Configuration
public class MvcConfig implements WebMvcConfigurer {

    @Resource
    private StringRedisTemplate stringRedisTemplate;

    //把啦凝结器添加进来
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new LoginIntercepetor())
                .excludePathPatterns( // 放行路径
                        "/shop/**",
                        "/vouchar/**",
                        "/shop-type/**",
                        "/upload/**",
                        "/blog/hot",
                        "/user/code",
                        "/user/login"
                ).order(1);
        registry.addInterceptor(new ReflushIntereptor(stringRedisTemplate))
                .addPathPatterns("/**").order(0);
    }

}
